﻿<UserControl x:Class="HighLandirect.Presentation.Views.OrderListView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:p="clr-namespace:HighLandirect.Presentation.Properties"
             xmlns:vm="clr-namespace:HighLandirect.Applications.ViewModels;assembly=HighLandirect.Applications"
             xmlns:c="clr-namespace:HighLandirect.Presentation.Converters"
             xmlns:r="clr-namespace:HighLandirect.Presentation.Resources"
             xmlns:v="clr-namespace:HighLandirect.Presentation.Behaviors"
             mc:Ignorable="d" d:DataContext="{d:DesignInstance vm:OrderListViewModel}">
    <DockPanel>
        <DockPanel.Resources>
            <ObjectDataProvider x:Key="productDataProvider" ObjectType="{x:Type r:Products}" MethodName="GetProducts"           />
            <ObjectDataProvider x:Key="storeDataProvider" ObjectType="{x:Type r:AdditionalData}" MethodName="GetStores"          />
            <ObjectDataProvider x:Key="reportMemoDataProvider" ObjectType="{x:Type r:AdditionalData}" MethodName="GetReportMemos" />
            <!--ObjectDataProvider x:Key="productDataProvider" ObjectType="{x:Type r:Products}"          /-->
            <!--ObjectDataProvider x:Key="storeDataProvider" ObjectType="{x:Type r:AdditionalData}"     /-->
            <!--ObjectDataProvider x:Key="reportMemoDataProvider" ObjectType="{x:Type r:AdditionalData}" /-->
            <c:ProductConverter x:Key="ProductConverter" />
        </DockPanel.Resources>
        <ToolBarTray DockPanel.Dock="Top">
            <ToolBar>
                <Button Command="{Binding PrintCommand}" Content="{x:Static p:Resources.Print}" Width="100" Background="#FFC6D2F5"/>
                <Button Command="{Binding RemoveCommand}" Content="{x:Static p:Resources.Remove}"/>
                <Separator />
                <TextBox Width="60" Text="{Binding SendCustomerId}"/>
                <Button Command="{Binding ShowOrderHistoryBySendCustomerCommand}" Width="80" Content="履歴を抽出"/>
                
            </ToolBar>
        </ToolBarTray>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="600"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="260"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <DataGrid ItemsSource="{Binding Orders}" SelectedItem="{Binding SelectedOrder}" 
                         SelectionChanged="ListViewSelectionChanged" AutoGenerateColumns="False" AlternationCount="1"
                         CanUserAddRows="False" FontSize="16">
                <DataGrid.Columns>
                    <DataGridTextColumn Binding="{Binding CustomerMasterSend.CustNo}" Header="{x:Static p:Resources.CustNo}" Width="60" IsReadOnly="True"/>
                    <DataGridTextColumn Binding="{Binding CustomerMasterSend.CustName}" Header="{x:Static p:Resources.CustName}" Width="150" IsReadOnly="True"/>
                    <DataGridTextColumn Binding="{Binding CustomerMasterReceive.CustNo}" Header="{x:Static p:Resources.CustNo}" Width="60" IsReadOnly="True"/>
                    <DataGridTextColumn Binding="{Binding CustomerMasterReceive.CustName}" Header="{x:Static p:Resources.CustName}" Width="150" IsReadOnly="True"/>

                    <DataGridTemplateColumn Header="品物" Width="100">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Path=ProductID, Mode=OneWay, Converter={StaticResource ProductConverter}, ConverterParameter=ProductName}" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                        <DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                                <ComboBox ItemsSource="{Binding Source={StaticResource productDataProvider}}"
                                          SelectedValue="{Binding ProductID}" SelectedValuePath="ProductID" DisplayMemberPath="ProductName" Margin="0,0,0,0" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellEditingTemplate>
                    </DataGridTemplateColumn>
                </DataGrid.Columns>
            </DataGrid>
            <Grid Grid.Column="1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="100"/>
                    <ColumnDefinition Width="100"/>
                    <ColumnDefinition Width="100"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="30" />
                    <RowDefinition Height="30" />
                    <RowDefinition Height="30" />
                    <RowDefinition Height="50" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <ComboBox Width="140" Height="30" Grid.ColumnSpan="2" HorizontalAlignment="Left"
                          ItemsSource="{Binding Source={StaticResource storeDataProvider}}"
                          SelectedItem="{Binding SelectedStore}" DisplayMemberPath="StoreName"
                          SelectionChanged="SendStoreSelectionChanged" FontSize="16" Margin="11,0,0,0" />
                <CheckBox IsChecked="{Binding SelectedStore.IsDefault}" Content="既定" Grid.Column="2" Grid.ColumnSpan="2" Margin="0,6,12,0" />
                <TextBlock Text="発店コード" Grid.Row="1" Margin="11,9,98,26" FontSize="20" Grid.ColumnSpan="2" Width="91" Height="25" Grid.RowSpan="2" />
                <TextBox Text="{Binding SelectedStore.StoreId1}" Width="60" Grid.Row="2" Margin="11,1,0,0" Height="29" FontSize="20" MinWidth="10" />
                <TextBox Text="{Binding SelectedStore.StoreId2}" Width="60" Grid.Row="2" Grid.Column="1"  Margin="0,1,0,0" Height="29" FontSize="20" MinWidth="10" />
            
                <TextBlock Text="お客様番号" Grid.Column="2" Height="21" Margin="0,9,0,0" Grid.Row="1" FontSize="20" Grid.ColumnSpan="2" />
                <TextBox Text="{Binding SelectedStore.CustomerCD}" Grid.Column="2" Margin="0,1,0,49" Grid.Row="2" Grid.ColumnSpan="2" FontSize="20" Height="30" Grid.RowSpan="2" Width="111" />
            
                <ComboBox Width="140" Height="30"  Grid.Row="3" Grid.ColumnSpan="2" HorizontalAlignment="Left"
                          ItemsSource="{Binding Source={StaticResource reportMemoDataProvider}}"
                          DisplayMemberPath="MemoName"
                          SelectedItem="{Binding SelectedReportMemo}" FontSize="16" Margin="11,20,0,0" />
                <CheckBox IsChecked="{Binding SelectedReportMemo.IsDefault}" Content="既定" Grid.Row="3" Grid.Column="2" Grid.ColumnSpan="2" Margin="0,30,11,0" />
                <TextBox Text="{Binding SelectedReportMemo.ReportMemo1}" Width="300" Height="100" Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="4"
                         TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Visible" FontSize="20"/>
            </Grid>
            <GridSplitter HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Height="4" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"/>
            <StackPanel Grid.Row="1" Grid.ColumnSpan="2" >
                <ToolBarTray >
                    <ToolBar>
                        <Button Command="{Binding AddOrderFromSelectedHistoryCommand}" Width="120" Content="履歴から注文を追加" Margin="0" />
                    </ToolBar>
                </ToolBarTray>
                <ListView ItemsSource="{Binding OrderHistories}" SelectedItem="{Binding SelectedOrderHistory}"
                  SelectionChanged="OrderHistorySelectionChanged">
                <ListView.View>
                    <GridView>
                        <GridViewColumn DisplayMemberBinding="{Binding OrderDate}" Header="注文日付" Width="100"/>
                        <GridViewColumn DisplayMemberBinding="{Binding CustomerMasterReceive.CustNo}" Header="{x:Static p:Resources.CustNo}" Width="60"/>
                        <GridViewColumn DisplayMemberBinding="{Binding CustomerMasterReceive.CustName}" Header="{x:Static p:Resources.CustName}" Width="150"/>
                        <GridViewColumn DisplayMemberBinding="{Binding CustomerMasterReceive.PostalCD}" Header="{x:Static p:Resources.PostalCD}" Width="40"/>
                        <GridViewColumn DisplayMemberBinding="{Binding CustomerMasterReceive.CityName}" Header="{x:Static p:Resources.CityName}" Width="50"/>
                        <GridViewColumn DisplayMemberBinding="{Binding CustomerMasterReceive.Address1}" Header="{x:Static p:Resources.Address1}" Width="150"/>
                        <GridViewColumn DisplayMemberBinding="{Binding CustomerMasterReceive.Address2}" Header="{x:Static p:Resources.Address2}" Width="150"/>
                        <GridViewColumn DisplayMemberBinding="{Binding CustomerMasterReceive.Phone}" Header="{x:Static p:Resources.Phone}" Width="100"/>
                        <GridViewColumn DisplayMemberBinding="{Binding CustomerMasterReceive.MailAddress}" Header="{x:Static p:Resources.MailAddress}" Width="100"/>
                        <GridViewColumn Header="{x:Static p:Resources.Label}" Width="30">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <CheckBox Content="{x:Static p:Resources.Label}" IsChecked="{Binding CustomerMasterSend.Label}" IsEnabled="False" />
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                    </GridView>
                </ListView.View>
            </ListView>
            </StackPanel>
        </Grid>
    </DockPanel>
</UserControl>
